"""
Author: HuWen
@file: page_security_supervision_info.py
@dateTime: 2025/7/7 11:13
加油加油！！！
"""
from playwright.sync_api import Page,expect
from common.base_page import BasePage
from common.logger import logger
from locators.basicSecurityInformation.loc_security_supervision_info import LocSecuritySupervisionInfo


class SecuritySupervisionInfoPage(BasePage):
    def __init__(self, page: Page):
        super().__init__(page)

    def edit_security_supervision_info(self):
        logger.info('开始编辑安全监管信息')
        self.click(LocSecuritySupervisionInfo.loc_safety_management_menu)
        self.click(LocSecuritySupervisionInfo.loc_security_supervision_tab)
        self.click(LocSecuritySupervisionInfo.loc_edit_button)

        self.select(LocSecuritySupervisionInfo.loc_color_select,"橙色")
        # self.click(LocSecuritySupervisionInfo.loc_color_yellow_option)

        self.select(LocSecuritySupervisionInfo.loc_department_select,"测试部门")
        # self.click(LocSecuritySupervisionInfo.loc_department_option)


        self.fill(LocSecuritySupervisionInfo.loc_office_phone, "02367524")

        self.select(LocSecuritySupervisionInfo.loc_leader_select,"ylt")

        self.fill(LocSecuritySupervisionInfo.loc_safety_duty_phone, "02367524161")
        self.fill(LocSecuritySupervisionInfo.loc_safety_production_license, "sb1234567")

        self.click(LocSecuritySupervisionInfo.loc_start_time)
        self.click(LocSecuritySupervisionInfo.loc_start_time_day_start)
        self.fill(LocSecuritySupervisionInfo.loc_start_time_day_start,"2025-01-01")
        self.click(LocSecuritySupervisionInfo.loc_start_time_day_end)
        self.fill(LocSecuritySupervisionInfo.loc_start_time_day_end,"2028-01-01")
        self.click(LocSecuritySupervisionInfo.loc_confirm_button)

        self.fill(LocSecuritySupervisionInfo.loc_employee_count, "30")
        self.clear_by_backspace(LocSecuritySupervisionInfo.loc_employee_number)
        self.fill_number(LocSecuritySupervisionInfo.loc_employee_number,10)
        # logger.info("focus强制清除元素内容")
        # self.page.locator(LocSecuritySupervisionInfo.loc_employee_number).focus()
        # self.page.keyboard.press("Control+A")
        # self.page.keyboard.press("Delete")
        # self.page.keyboard.type("15")
        # locator = self.page.locator(LocSecuritySupervisionInfo.loc_employee_number)
        # locator.press_sequentially("1",delay=300,timeout=500)
        # locator.fill("15", force=True)  # 强制填充，忽略禁用状态

        self.clear_by_backspace(LocSecuritySupervisionInfo.loc_safety_manager_count)

        self.fill_number(LocSecuritySupervisionInfo.loc_safety_manager_count, 11)

        self.clear_by_backspace(LocSecuritySupervisionInfo.loc_registered_engineer_count)

        self.fill_number(LocSecuritySupervisionInfo.loc_registered_engineer_count, 5)
        self.fill(LocSecuritySupervisionInfo.loc_poisonous_chemical_worker_count, "6")
        self.fill(LocSecuritySupervisionInfo.loc_dangerous_chemical_worker_count, "7")
        self.fill(LocSecuritySupervisionInfo.loc_special_worker_count, "8")
        # 这个地方还没调试完毕，这个定位还有问题
        # self.upload_attachment(LocSecuritySupervisionInfo.loc_upload_button,file_path="C:\\Users\\Administrator\\Desktop\\年假.png",delete_existing=False)


        self.check(LocSecuritySupervisionInfo.loc_is_hazardous_chemical_enterprise, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_special_equipment, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_limited_space_operation, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_fire_key_unit, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_ammonia_involved, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_occupational_hazard, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_hazardous_chemical_pipeline, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_explosive_dust_operation, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_coal_gas_involved, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_special_worker, "否")
        self.check(LocSecuritySupervisionInfo.loc_is_major_hazard_source, "否")

        self.click(LocSecuritySupervisionInfo.loc_submit_button)